# Additionnal drag modes (other plug-ins may add other drag modes).
#
parent = quarkpy.qhandles.RectangleDragObject
class EntRectSelDragObject(parent):
"A red rectangle that selects the entities it touches."
Hint = hintPlusInfobaselink("Rectangular selection of ENTITIES||Rectangular selection of ENTITIES:\n\nThis works like 'rectangular selection of polyhedron' (just on the left), but selects entities instead of polyhedrons.", "intro.mapeditor.toolpalettes.mousemodes.html#selectentity")
def rectanglesel(self, editor, x,y, rectangle):
if not ("T" in self.todo):
editor.layout.explorer.uniquesel = None
entlist = FindSelectable(editor.Root, ":e")
lastsel = None
for e in entlist:
org = e.origin
if org is None: continue
for f in rectangle.faces:
if org*f.normal > f.dist:
break
else: # the point is inside the polyhedron
e.selected = 1
lastsel = e
if lastsel is not None:
editor.layout.explorer.focus = lastsel
editor.layout.explorer.selchanged()
class EverythingRectSelDragObject(parent):
"A red rectangle that selects the entities it touches."
Hint = hintPlusInfobaselink("Rectangular selection of EVERYTHING||Rectangular selection of EVERYTHING:\n\nThis works like 'rectangular selection of polyhedron' (just on the left), but selects everything including duplicators and beziers.", "intro.mapeditor.toolpalettes.mousemodes.html#selecteverything")
Hint = hintPlusInfobaselink("Quick cube maker||Quick cube maker:\n\nAfter you click this button, you can draw rectangles on the map with the mouse button and these rectangles will be turned into actual cubes. This is a quick way to make a lot of cubes all around.", "intro.mapeditor.toolpalettes.mousemodes.html#createcube")
newface.setthreepoints((center, center + v * sign, center + (n^v) * 128), 0)
newpoly.appenditem(newface)
undo.put(newgroup, newpoly)
undo.exchange(poly, None)
undo.exchange(sellist[0], None)
editor.ok(undo, "cut face in two")
return
sellist = editor.visualselection()
if len(sellist)==0:
sellist = [editor.Root]
elif len(sellist)==1 and sellist[0].type==':g':
#
# Special : if a group is selected, we just insert the new face in the group.
# First ask the user if he agrees...
#
todo = quarkx.msgbox("You are cutting a whole group in two parts. Do you want to try making two groups with a single global face for each group ? If you answer No, the selected polyhedrons will be individually cut in two parts.",
newface.setthreepoints((center, center + v * 128, center + (n^v) * 128), 0)
undo.put(sellist[0], newface)
editor.ok(undo, "cut in two groups", [sellist[0], newgroup])
return
polylist = []
for obj in sellist:
polylist = polylist + obj.findallsubitems("", ':p') # find all polyhedrons
#
# Cut the polyhedrons in polylist
#
autoremove = polylist[:]
undo = quarkx.action()
for p in polylist:
if p.intersects(face):
#
# We must cut this polyhedron in two parts.
# Find a "model" face for the new one.
# This model face must be cutted in two.
#
bestface = None
minnormal = 9
for f1 in p.faces:
vtx = f1.verticesof(p)
gotv1 = vtx[-1]
prevv = gotv1*n < face.dist
for v in vtx:
nextv = v*n < face.dist # 0 or 1
if prevv+nextv==1: # the two vertices are not on the same side of the cutting plane
gotv2 = v
break
prevv = nextv
gotv1 = v
else:
continue # this face doesn't cross the cutting plane
test = choicefn(face, f1.normal)
if test<minnormal:
minnormal = test
bestface = f1
bestv1 = gotv1
bestv2 = gotv2
if bestface is None:
continue # should not occur
#
# Build the new face.
#
newface = bestface.copy()
newface.shortname = "cut"
#
# Rotate the face to its correct position.
#
f = (bestv2*n - face.dist) / (bestv2*n - bestv1*n)
center = bestv1*f + bestv2*(1-f) # the intersection of the edge "bestv1->bestv2" with the plane
newface.distortion(n, center)
#
# Insert the new face into the polyhedron.
#
undo.put(p, newface)
#
# Do it again with the other orientation to make the other half.
#
p2 = p.copy()
newface = bestface.copy()
newface.shortname = "cut"
newface.distortion(-n, center)
p2.appenditem(newface)
undo.put(p.parent, p2, p.nextingroup())
autoremove.append(p2)
editor.ok(undo, "cut in two", autoremove)
class CubeCutter(parent):
"Cuts polyhedrons in two parts along the line drawn."
Hint = hintPlusInfobaselink("Cut faces, polyhedrons and groups in two||Cut faces, polyhedrons and groups in two:\n\nAfter you click this button, you can draw lines on the map with the mouse, and any polyhedron touching this line will be cut in two parts along it. This is a quick way to make complex shapes out of a single polyhedron. You can for example draw 3 lines in a wall to make the contour of a passage, and then just delete the middle polyhedron to actually make the hole.\n\nAdvanced features : if you select a face, it will be cut in two but not the other faces of the polyhedron (using \"face sharing\" techniques); and if you select a group, instead of cutting each polyhedron in two individually, QuArK will give you the option of making two copies of the whole group with the cutting plane as a shared face in each group. This lets you consider the cutting plane as a unique face and later move or rotate it to reshape all polyhedrons in the group at once.", "intro.mapeditor.toolpalettes.mousemodes.html#polycutter")